﻿///* 
// * author: www.cnblogs.com/luminji
// * date  : 2012/07/21
// */
//using System.Web.Mvc;
//using Luminji.Core.Web.Cookie;
//using Luminji.Core.Web.Mockes;
//using Luminji.Exam.Model.Users;
//using Luminji.ExamWeb.Models;
//using Microsoft.VisualStudio.TestTools.UnitTesting;

//namespace Luminji.ExamWeb.Tests.Web.Controllers.Account
//{
//    [TestClass]
//    public class AccountControllerLoginTest : AccountControllerTest
//    {
//        [TestMethod]
//        public void ShouldShowNotExistedIfGetNull()
//        {
//            LogOnModel user1 = new LogOnModel() { Password = "xxx", UserName = "abc123" };
//            _mock.Setup(service => service.CheckUser("abc123", "xxx")).Returns(LoginState.UserNotExsisted);
//            _controller.LogOn(user1, "");
//            Assert.AreEqual("对不起，当前用户不存在！", _controller.ViewBag.LoginError);
//        }

//        [TestMethod]
//        public void ShouldShowKeyWrongIfKeyWrong()
//        {
//            LogOnModel user1 = new LogOnModel() { Password = "123xxx", UserName = "abc" };
//            _mock.Setup(service => service.CheckUser("abc", "123xxx")).Returns(LoginState.PasswordWrong);
//            _controller.LogOn(user1, "");
//            Assert.AreEqual("对不起，密码错误，请重新输入！", _controller.ViewBag.LoginError);
//        }

//        [TestMethod]
//        public void ShouldRedirectToHomeWhenLogin()
//        {
//            RedirectToRouteResult re = LoginCorrected() as RedirectToRouteResult;
//            Assert.AreEqual("Account", re.RouteValues["controller"]);
//            Assert.AreEqual("Index", re.RouteValues["action"]);
//        }

//        [TestMethod]
//        public void ShouldSetCookieWhenLogin()
//        {
//            var re = LoginCorrected();
//            var userExpected = CookieHelper.GetCookieValue<LogOnModel>(_controller.Request, "LogOnModel");
//            Assert.AreEqual("abc", userExpected.UserName);
//        }

//        private ActionResult LoginCorrected()
//        {
//            LogOnModel user1 = new LogOnModel() { Password = "123", UserName = "abc" };
//            return _controller.LogOn(user1, "");
//        }

//        [TestMethod]
//        public void ShouldClearCookieWhenLogOff()
//        {
//            ShouldSetCookieWhenLogin();
//            var re = _controller.LogOff();
//            var expect = CookieHelper.GetCookieValue<LogOnModel>(_controller.Request, "LogOnModel");
//            Assert.IsNull(expect);
//        }

//        [TestMethod]
//        public void ShouldRedirectToHomeWhenLogOff()
//        {
//            LoginCorrected();
//            var re = _controller.LogOff() as RedirectToRouteResult;
//            Assert.AreEqual("Home", re.RouteValues["controller"]);
//            Assert.AreEqual("Index", re.RouteValues["action"]);
//        }
//    }
//}
